package leetcode.Y2024M6.study;

import leetcode.Y2024M6.TreeNode;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

public class S98 {
    private List<Integer> list = new ArrayList<>();

    public boolean isValidBST(TreeNode root) {
        midView(root);
        for (int i = 1; i < list.size(); i++) {
            if (list.get(i) <= list.get(i - 1)) return false;
        }
        return true;
    }

    private void midView(TreeNode root) {
        if (root == null) return;
        midView(root.left);
        list.add(root.val);
        midView(root.right);
    }

    @Test
    public void test() {

    }
}
